package customer.zspt.cn.customer.Adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import customer.zspt.cn.customer.components.chat.chatMore.ChildPager.ChatMoreChildPager;

/**
 * Created by Administrator on 2018/7/22 0022.
 */

public class MoreVpAdapter extends PagerAdapter {
    List<ChatMoreChildPager> pg;

    public MoreVpAdapter(List<ChatMoreChildPager> pg)
    {
        this.pg = pg;
    }
    @Override
    public int getCount() {
        return pg.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object ;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = pg.get(position).mRootView;
        pg.get(position).setGetTitleLintener(new ChatMoreChildPager.GetTileLintener() {
            @Override
            public void getTitle(String title) {
                 if(mLintener!=null)
                 {
                     mLintener.getMoreItemTitle(title);
                 }
            }
        });
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    private getTitleLintener mLintener;
    public interface getTitleLintener{
        void getMoreItemTitle(String title);
    }

    public void getItemTitle(getTitleLintener Lintener)
    {
        mLintener = Lintener;
    }
}
